﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Supply_Fetch
{
    public partial class DidYouMeanDialog : Form
    {

        private List<Item> AllItems = new List<Item>();
        private string interpretedItem;
        private string selecteditem;

        public DidYouMeanDialog(string item, float confval,string[] itemNames)
        {
            InitializeComponent();
            interpretedItem = item;
            CreateAccordion();
            RecognizedWordLabel.Text = item+" ("+confval.ToString()+")";

            this.AllItemsComboBox.Items.Clear();
            this.AllItemsComboBox.Items.AddRange(itemNames);
            this.AllItemsComboBox.Sorted = true;
        }

        private void CreateAccordion()
        {
            Accordion accordion = new Accordion();
            accordion.Dock = DockStyle.Fill;

            Expander expander1 = new Expander();
            expander1.BorderStyle = BorderStyle.FixedSingle;
            ExpanderHelper.CreateLabelHeader(expander1, "Did you mean the item below?", SystemColors.ActiveCaption,Properties.Resources.Collapse ,Properties.Resources.Expand, 35, new Font("Arial", 12, FontStyle.Bold));
            expander1.Content = panel1;
            accordion.Add(expander1);

            Expander expander2 = new Expander();
            expander2.BorderStyle = BorderStyle.FixedSingle;
            ExpanderHelper.CreateLabelHeader(expander2, "Select an item from the list", SystemColors.ActiveCaption, Properties.Resources.Collapse, Properties.Resources.Expand, 35, new Font("Arial", 12, FontStyle.Bold));
            expander2.Content = panel2;
            accordion.Add(expander2);

            this.Controls.Add(accordion);
        }

        private void CreateContentLabel(Expander expander, string text, int height)
        {
            Label labelContent = new Label();
            labelContent.Text = text;
            labelContent.Size = new System.Drawing.Size(expander.Width, height);
            expander.Content = labelContent;
        }

        private void YesButton_Click(object sender, EventArgs e)
        {
            selecteditem=interpretedItem;
            DialogResult = DialogResult.OK;
        }

        private void NoButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
        /*
        private void OkButton_Click(object sender, EventArgs e)
        {
            this.selecteditem = AllItemsComboBox.SelectedItem.ToString();
            DialogResult = DialogResult.OK;
        }*/

        private void CancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        public string SelectedItem
        {
            get { return selecteditem; }
        }

        /*****/
        private void AllItemsComboBox_Entered(object sender, EventArgs e)
        {
            this.AllItemsComboBox.Text = null;
            this.AllItemsComboBox.Font = new Font(this.AllItemsComboBox.Font.FontFamily, this.AllItemsComboBox.Font.Size, FontStyle.Regular);
            this.AllItemsComboBox.ForeColor = Color.Black;
        }

        private void AllItemsComboBox_EnterKey(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
            {
                AllItemsComboBox_ItemSelected(sender, e);
            }
        }

        private void AllItemsComboBox_ItemSelected(object sender, EventArgs e)
        {
            if ((this.AllItemsComboBox.Text == null) || (this.AllItemsComboBox.Text == "") || (this.AllItemsComboBox.Text == "Select an item from the list..."))
            {
                MessageBox.Show("Please select item from list before attempting to locate.", "Please Select Item First", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                this.AllItemsComboBox.Text = "Select an item from the list...";
                this.AllItemsComboBox.Font = new Font(this.AllItemsComboBox.Font.FontFamily, this.AllItemsComboBox.Font.Size, FontStyle.Italic);
                this.AllItemsComboBox.ForeColor = Color.Gray;
                this.AllItemsComboBox.Enabled = false;
                this.AllItemsComboBox.Enabled = true;
            }
            else
            {
                this.selecteditem = AllItemsComboBox.SelectedItem.ToString();
                DialogResult = DialogResult.OK;
            }
        }
    }
}
